package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.Pages;
import io.renren.common.utils.ResponseModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.sys.entity.SysDictionaryEntity;
import io.renren.modules.sys.service.SysDictionaryService;
import io.renren.common.utils.PageUtils;



/**
 * 字典表
 *
 * @author xwj
 * @email sunlightcs@gmail.com
 * @date 2021-07-01 14:45:23
 */
@RestController
@RequestMapping("/sys/sysdictionary")
@Api(tags = "后台管理-字典管理")
public class SysDictionaryController {
    @Autowired
    private SysDictionaryService sysDictionaryService;

    @PostMapping("/dictionary")
    @ApiOperation("根据字典类别查询字典")
    public ResponseModel<List<SysDictionaryEntity>> dictionary(@RequestBody SysDictionaryEntity sysDictionary) {
        List<SysDictionaryEntity> list = sysDictionaryService.loadDictionary(sysDictionary);
        return ResponseModel.of(list);
    }

    /**
     * 列表
     */
    @PostMapping("/list")
    @RequiresPermissions("sys:sysdictionary:list")
    @ApiOperation("字典列表")
    public ResponseModel<Pages<SysDictionaryEntity>> list(@RequestBody SysDictionaryEntity sysDictionaryEntity) {
        Pages<SysDictionaryEntity> pages = sysDictionaryService.queryPage(sysDictionaryEntity);
        return ResponseModel.of(pages);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("sys:sysdictionary:info")
    @ApiOperation("字典详情信息")
    public ResponseModel<SysDictionaryEntity> info(@PathVariable("id") Long id){
		SysDictionaryEntity sysDictionary = sysDictionaryService.getById(id);

        return ResponseModel.of(sysDictionary);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("sys:sysdictionary:save")
    @ApiOperation("新增字典")
    public ResponseModel save(@RequestBody SysDictionaryEntity sysDictionary){
		sysDictionaryService.save(sysDictionary);

        return ResponseModel.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("sys:sysdictionary:update")
    @ApiOperation("修改字典")
    public ResponseModel update(@RequestBody SysDictionaryEntity sysDictionary){
		sysDictionaryService.updateById(sysDictionary);

        return ResponseModel.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("sys:sysdictionary:delete")
    @ApiOperation("删除字典")
    public ResponseModel delete(@RequestBody Long[] ids){
		sysDictionaryService.removeByIds(Arrays.asList(ids));

        return ResponseModel.ok();
    }

}
